React = require('react')
Card = require('antd-mobile/lib/card')
# ListView = require('antd-mobile/lib/list-view')
Flex = require('antd-mobile/lib/flex')
Icon = require('antd-mobile/lib/icon')
Toast = require('antd-mobile/lib/toast')
RefreshControl = require('antd-mobile/lib/refresh-control')
TopNotice = require('antd-mobile/lib/notice-bar')
{StyleSheet,WebView,View,Image,Text,ScrollView,TouchableHighlight,StyleSheet,Navigator,ListView,ActivityIndicator,TouchableOpacity} = require('react-native')
Dimensions = require('Dimensions')
{ width, height } = Dimensions.get('window')
{View} = require('react-native')
{fetchGetList,fetchRefreshList} = require('../actions/page_planDetail.js')
{connect} = require('react-redux')
_ = require('underscore')
moment = require('moment')
backImg = require('../img/back.png')
searchIcon = require('../img/search_white.png')
BaseWebView = require('../mixins/baseWebView.js')
ActionSheet = require('antd-mobile/lib/action-sheet')
TimerMixin = require('react-timer-mixin')

Web_Dtcxb = React.createClass
  mixins:[TimerMixin]
  onLoadingError:->
    <View>
      <Text>数据加载失败，请重试</Text>
    </View>
  getInitialState:->
    loadingError:false
    area:0
    visibility:1
    hish:""
  renderHeader:->
    <View style={{flexDirection:'row',flex:0,height:60,alignItems:'center', justifyContent:'center',backgroundColor:'#0066FF'}}>
      <View style={{flex:1,padding:10}}>
        <TouchableOpacity onPress={=>@props.navigator.pop()}>
          <Image source={backImg}  style={{height:30,width:30,resizeMode:'contain'}}/>
        </TouchableOpacity>
      </View>
      <View style={{flex:3,justifyContent:'center',alignItems:'center'}}>
        <Text style={{fontSize:20,color:'#ffffff'}}>动态潮汐表</Text>
      </View>
      <View style={{flex:1,alignItems:'flex-end',padding:10}}>
      </View>
    </View>
  source:->
    uri:"http://202.136.214.173/Home/TidePage"
  injectedJavaScript:->
    # """
    #   $('.ad').hide();
    #   var logo = $('.logo');
    #   logo.empty();
    #   logo.next().attr('href','#');
    # """
  handleNavigationStateChange:(e)->
    debugger;
    that = @
    url = e.url
    if url.indexOf('?') isnt -1
      t = url.substring url.indexOf('?')+1
      that.setState hish:t
      # t = url.substring url.indexOf('?')+1
      # that.setState visibility:0,->
      #     that.setState hish:t,->
      #       #延迟一秒后显示
      #       setTimeout ->
      #         that.setState visibility:1
      #       ,600
  handleOnLoadStart:->
    @setState visibility:0
  handleOnLoad:->
    that = @
    that.setTimeout ->
      that.setState visibility:1
    ,1000
  render:->
    <View style={width:width,height:height,flexDirection:'column',backgroundColor:'#ffffff'}>
      {@renderHeader()}
      {
        if @props.connected
          <WebView
            style={{flex:1,opacity:@state.visibility}}
            ref="webView"
            startInLoadingState=true
            renderError={@onLoadingError}
            injectedJavaScript={@injectedJavaScript()}
            javaScriptEnabled={true}
            domStorageEnabled={true}
            source={@source()}
            onNavigationStateChange={@handleNavigationStateChange}
            onLoadStart ={@handleOnLoadStart}
            onLoad={@handleOnLoad}
            >
          </WebView>
      }
    </View>


mapStateToProps = (state)->
  userInfo:state.userInfo
  connected:state.appState.connected
module.exports = connect(mapStateToProps)(Web_Dtcxb)
